using System;
using System.Reflection;
using DemoPress.BlogDomain;
using DemoPress.BlogDataServices;

namespace DemoPress.BlogServices
{
    public class BlogService
    {
        private static object SyncRoot = new Object();
        private DemoPress.BlogDomain.Blog _blog;
        private Theme _theme;
        private IDemoPressDataService _dataService;

        public DemoPress.BlogDomain.Blog Blog
        {
            get
            {
                if (_blog == null)
                {
                    _blog = new DemoPress.BlogDomain.Blog();
                    _blog.Name = DataService.BlogData.GetBlogName();
                }
                return _blog;
            }
            set { _blog = value; }
        }

        public Theme Theme
        {
            get
            {
                if (_theme == null)
                {
                    _theme = new Theme();
                    _theme.Path = DataService.BlogData.GetThemePath();
                }
                return _theme;
            }
            set { _theme = value; }
        }

        internal IDemoPressDataService DataService
        {
            get { return _dataService; }
        }

        private BlogService(IDemoPressDataService dataService)
        {
            _dataService = dataService;
        }

        static public BlogService CreateService(string assembly, string dataService)
        {
            Assembly a = AppDomain.CurrentDomain.Load(assembly);
            object obj = a.CreateInstance(dataService);
            return CreateService((IDemoPressDataService)obj);
        }

        static public BlogService CreateService(IDemoPressDataService dataService)
        {
            return new BlogService(dataService);
        }


    }
}
